package org.jeecg.modules.basic.report.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.basic.report.entity.GoodsReport;
import org.jeecg.modules.basic.report.entity.PersonReport;
import org.jeecg.modules.basic.report.entity.WxScatter;
import org.jeecg.modules.basic.report.mapper.GoodsReportMapper;
import org.jeecg.modules.basic.report.service.GoodsReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.*;

/**
 * TODO
 *
 * @author sn
 * @date 2021-09-27 13:34
 */
@Service
public class GoodsReportServiceImpl extends ServiceImpl<GoodsReportMapper, GoodsReport> implements GoodsReportService {
    @Autowired
    private GoodsReportMapper goodsReportMapper;

    @Override
    public List<GoodsReport> findGoodsReport(GoodsReport goodsReport) {
        String dimension = goodsReport.getDimension();
        if(dimension == null){
            goodsReport.setDimension(" YEAR(create_time) ");
            goodsReport.setTime(" concat( year(create_time),'年') ");
        }else{
            if(dimension.equals("month")){
                goodsReport.setDimension(" YEAR(create_time), MONTH(create_time) ");
                goodsReport.setTime(" concat( year(create_time),'年',MONTH(create_time),'月') ");

            }else if(dimension.equals("week")){
                goodsReport.setDimension(" YEAR(create_time), MONTH(create_time), WEEK(create_time) ");
                goodsReport.setTime(" concat( year(create_time),'年',MONTH(create_time),'月,', WEEK(create_time),'周') ");
            }else{
                goodsReport.setDimension(" YEAR(create_time) ");
                goodsReport.setTime(" concat( year(create_time),'年') ");
            }
        }


        List<GoodsReport> goodsReportList = goodsReportMapper.findGoodsReport(goodsReport);
        return goodsReportList;
    }

    @Override
    public List<PersonReport> findPersonReport(PersonReport personReport) {
        String dimension = personReport.getDimension();
        if(dimension == null){
            personReport.setDimension(" YEAR(create_time) ");
            personReport.setTime(" concat( year(create_time),'年') ");
        }else{
            if(dimension.equals("month")){
                personReport.setDimension(" YEAR(create_time), MONTH(create_time) ");
                personReport.setTime(" concat( year(create_time),'年',MONTH(create_time),'月') ");

            }else if(dimension.equals("week")){
                personReport.setDimension(" YEAR(create_time), MONTH(create_time), WEEK(create_time) ");
                personReport.setTime(" concat( year(create_time),'年',MONTH(create_time),'月,', WEEK(create_time),'周') ");
            }else{
                personReport.setDimension(" YEAR(create_time) ");
                personReport.setTime(" concat( year(create_time),'年') ");
            }
        }


        List<PersonReport> personReportList = goodsReportMapper.findPersonReport(personReport);
        return personReportList;
    }

    public  List<WxScatter> findLhPlaceList(@RequestParam(name="ids",required=true) String ids){
        //获取楼宇分布
        List<String> id=Arrays.asList( ids.split(","));
        ids = String.format("'%s'", String.join("','", id));
        List<WxScatter> map = goodsReportMapper.findLhPlaceList(ids);
        return map;

    }

    public  List<WxScatter> findPersonList(@RequestParam(name="ids",required=true) String ids){
        //获取维修人员分布

        List<String> id=Arrays.asList( ids.split(","));
        ids = String.format("'%s'", String.join("','", id));
        List<WxScatter> map = goodsReportMapper.findPersonList(ids);
        return map;

    }



    public  List<WxScatter> findGoodsList(@RequestParam(name="ids",required=true) String ids) {
        //获取维修人员分布

        List<String> id = Arrays.asList(ids.split(","));
        ids = String.format("'%s'", String.join("','", id));
        List<WxScatter> map = goodsReportMapper.findGoodsList(ids);
        return map;
    }



  /*  @Override
    public Map<String, Integer> getNoneRoomByCampus(String campus) {
        List<HotelRoom> hotelRooms = bxReportMapper.getNoneRoomByCampus(campus);
        Map<String,Integer> map = new LinkedHashMap();
        for (HotelRoom hotelRoom : hotelRooms) {
            map.put(hotelRoom.getName(),hotelRoom.getNumber());
        }
        map.put("type",0);//空房间
        return map;
    }

    @Override
    public Map<String, Integer> getUnderRoomByCampus(String campus) {
        List<HotelRoom> hotelRooms = bxReportMapper.getUnderRoomByCampus(campus);
        Map<String,Integer> map = new LinkedHashMap();
        for (HotelRoom hotelRoom : hotelRooms) {
            map.put(hotelRoom.getName(),hotelRoom.getNumber());
        }
        map.put("type",1);//未满房间
        return map;
    }

    @Override
    public List<HotelRoom> getList(String campus) {
        List<HotelRoom> underRoomList = bxReportMapper.getUnderRoomByCampus(campus);//未满房间
        List<HotelRoom> noneRoomList = bxReportMapper.getNoneRoomByCampus(campus);//空房间
        List<HotelRoom>list = new ArrayList<>();
        for (int i = 0; i < underRoomList.size(); i++) {
            HotelRoom noneRoom = noneRoomList.get(i);
            HotelRoom underRoom = underRoomList.get(i);
            noneRoom.setUnderNumber(underRoom.getNumber());
            list.add(noneRoom);
        }
        return list;
    }

    @Override
    public IPage<HotelRoom> queryPageListCustom(Page<HotelRoom> page, String campus) {
        List<HotelRoom> list = getList(campus);
        return page.setRecords(list);
    }

    @Override
    public List<RoomReport> roomUseReport(RoomReport roomReport) {
        String dimension = roomReport.getDimension();
        if(dimension == null){
            roomReport.setDimension("campus_id");
            roomReport.setName("campus_name");
        }else{
            if(dimension.equals("campus_id")){
                roomReport.setName("campus_name");
            }else if(dimension.equals("building_id")){
                roomReport.setName("building_name");
            }
        }
        return bxReportMapper.roomUseReport(roomReport);
    }

    @Override
    public List<BedReport> bedUseReport(BedReport bedReport) {
        String dimension = bedReport.getDimension();
        if(dimension == null){
            bedReport.setDimension("campus_id");
            bedReport.setName("campus_name");
        }else{
            if(dimension.equals("campus_id")){
                bedReport.setName("campus_name");
            }else if(dimension.equals("building_id")){
                bedReport.setName("building_name");
            }
        }
        return bxReportMapper.bedUseReport(bedReport);
    }*/
}
